<template>
  <div id="head" style="margin-top: 20px">
    <el-button
      type="primary"
      size="mini"
      style="margin: 1%"
      @click="drawer1 = true">挂号病患列表</el-button>
    <el-drawer
      title="已挂号病患列表"
      :visible.sync="drawer1"
      :direction="direction">
      <registrationIndex v-on:regOutpatientListen="listenRegOutpatientForm"></registrationIndex>
    </el-drawer>
    <el-form ref="form" :model="totalPatientForm" >
    <el-row>
      <el-col :span="24">
        <el-button type="primary" icon="el-icon-arrow-right" circle></el-button>
        <span class="title">当前病人:</span>
        <el-form-item v-if="idHid" label="ID" class="outpatient" prop="patientId">
        <el-input v-model="totalPatientForm.patientId"/>
        </el-form-item>
        <el-form-item  label="姓名" class="outpatient" prop="name">
        <el-input v-model="totalPatientForm.name" disabled/>
        </el-form-item>
        <el-form-item label="就诊号" class="outpatient" prop="medicalRecordNo">
        <el-input v-model="totalPatientForm.medicalRecordNo" disabled/>
        </el-form-item>
        <el-form-item label="性别" class="outpatient" prop="gender">
        <el-input v-model="totalPatientForm.gender" disabled/>
        </el-form-item>
        <el-form-item label="年龄" class="outpatient" prop="ageStr">
        <el-input v-model="totalPatientForm.ageStr" disabled/>
        </el-form-item>
          <el-divider></el-divider>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-tabs v-if="frontHide" v-model="activeName" type="card">
          <el-tab-pane label="病历首页" name="medicalRecord" :disabled="medicalRecordDis">
            <outpatientPage v-bind:historyOutPatientDataListen="historyOutPatientData" v-bind:front="frontHide" ref="patListen" @outPatientFormListen="outPatientPageForm"></outpatientPage>
          </el-tab-pane>
          <el-tab-pane label="检查申请" name="inspect"></el-tab-pane>
          <el-tab-pane label="检验申请" name="test"><nonDrugTest :param="totalPatientForm" v-bind:front="frontHide"></nonDrugTest></el-tab-pane>
          <el-tab-pane label="门诊确诊" name="diagnosis"></el-tab-pane>
          <el-tab-pane label="成药处方" name="patentMedicine"></el-tab-pane>
          <el-tab-pane label="草药处方" name="herbalMedicine"></el-tab-pane>
          <el-tab-pane label="处置申请" name="disposalApplication"></el-tab-pane>
          <el-tab-pane label="患者账单" name="patientBill"></el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>
    </el-form>
  </div>
</template>

<script>
  import { addCase_history,getPatientAndReg} from "@/api/dms/outpatient";
  import outpatientPage from "../outpatient_page/index";
  import registrationIndex from "../registration/index";
  import nonDrugTest from "../non_drug_test/index";
  export default {
    components: {outpatientPage, registrationIndex,nonDrugTest},
    data() {
      return {
        medicalRecordDis:false,
        //前置操作之后显示界面
        frontHide:false,
        idHid: false,
        totalPatientForm: {
          registrationId: '',
          patientId: '',
          patientMedicalRecordNo: '',
          name: '',
          ageStr: '',
          gender: '',
          chiefComplaint: '',
          historyOfPresentIllness: '',
          historyOfTreatment: '',
          pastHistory: '',
          allergies: '',
          healthCheckup: '',
          startDate: '',
          priliminaryDiseIdList: '',
          priliminaryDiseStrList: '',
        },
        direction: 'ltr',
        drawer1: false,
        activeName: 'medicalRecord',
        //控制历史病历的数据 父组件传递子组件
        historyOutPatientData: [],
      };
    },
    created() {

    },
    methods: {
      outPatientPageForm: function (data) {
        this.totalPatientForm.chiefComplaint = data[0].chiefComplaint;
        this.totalPatientForm.historyOfPresentIllness = data[0].historyOfPresentIllness;
        this.totalPatientForm.historyOfTreatment = data[0].historyOfTreatment;
        this.totalPatientForm.pastHistory = data[0].pastHistory;
        this.totalPatientForm.allergies = data[0].allergies;
        this.totalPatientForm.healthCheckup = data[0].healthCheckup;
        this.totalPatientForm.startDate = data[0].startDate;
        var assessmentIdList = '';
        var assessmentStrList = '';
        for (var i = 0; i < data[1].length; i++) {
          assessmentIdList += data[1][i].id + ",";
          assessmentStrList += data[1][i].name + ",";
        }
        this.$refs["form"].validate(valid => {
          if (valid) {
            var sex = '';
            if (this.totalPatientForm.gender == '男') {
              sex = 0;
            } else {
              sex = 1;
            }
            this.totalPatientForm.gender = sex;
            this.totalPatientForm.priliminaryDiseIdList = assessmentIdList;
            this.totalPatientForm.priliminaryDiseStrList = assessmentStrList;
            addCase_history(this.totalPatientForm).then(response => {
              if (response.code === 200) {
                if(this.totalPatientForm.gender ==0){
                  sex = '男'
                }else{
                  sex = '女'
                }
                this.totalPatientForm.gender = sex;
                this.msgSuccess("新增成功");
                this.open = false;
                this.medicalRecordDis =true;
                this.activeName = 'inspect';
              }
            })
          }
        })
      },
      //父组件传值到子组件监听方法
      listenRegOutpatientForm: function (data) {
          getPatientAndReg(data.patientId).then(response => {
            var sex = '';
            if (response.data.gender == 1) {
              sex = '女'
            } else {
              sex = '男'
            }
            this.totalPatientForm.patientId = data.patientId;
            this.totalPatientForm.registrationId = data.registrationId;
            this.totalPatientForm.medicalRecordNo = data.medicalRecordNo;
            this.totalPatientForm.name = data.name;
            this.totalPatientForm.ageStr = data.patientAgeStr;
            this.totalPatientForm.gender = sex;
            this.frontHide = true;
            /* getCase_patHistory(data.patientId).then(response => {
               if (response.rows != undefined) {
                 this.historyOutPatientData = response.rows;
               } else {
                 const h = this.$createElement;
                 this.$notify({
                   title: '提示',
                   message: h('i', {style: 'color: teal'}, '此病患无历史病历')
                 });
               }
             })*/
          })
      },
    }
  }
</script>
<style>
  .outpatient{
    display: inline-block;
    margin-left: 10px;
    margin-right: 20px;
    width: 15%;
  }
  .title{
    margin-left: 20px;
  }
  #head{
    margin: auto;
    left: 0;
    right: 0;
    width: 96%;
  }

</style>
